FROM node:22-alpine AS build

RUN npm install -g corepack && corepack enable

COPY --from=golang:1.23.5-alpine /usr/local/go/ /usr/local/go/

ENV PATH="/usr/local/go/bin:${PATH}"

WORKDIR /daytona

COPY . .

ARG VERSION=0.0.1
ENV VERSION=${VERSION}

RUN yarn

RUN yarn nx build ssh-gateway --configuration=production --nxBail=true

FROM alpine:3.18 AS ssh-gateway

WORKDIR /usr/local/bin

COPY --from=build /daytona/dist/apps/ssh-gateway daytona-ssh-gateway

RUN chmod +x daytona-ssh-gateway

ENV API_URL=http://api:3000/api
ENV API_KEY=ssh_secret_api_token
ENV SSH_PRIVATE_KEY="LS0tLS1CRUdJTiBPUEVOU1NIIFBSSVZBVEUgS0VZLS0tLS0KYjNCbGJuTnphQzFyWlhrdGRqRUFBQUFBQkc1dmJtVUFBQUFFYm05dVpRQUFBQUFBQUFBQkFBQUJsd0FBQUFkemMyZ3RjbgpOaEFBQUFBd0VBQVFBQUFZRUEzaW9hVmpXbDFPaVVkcTFzeHVlbFNNeXZxNVByV2ZxZmxFWmRzbXNxbllIWWVwN2pmMHBsCmE1VzNzZElwQkZXTTRFR0FkR2MvZDRJL1Y2aVJzV2RtOUxvUjliT2liNThTWGxoL2paSjlETitHeGVuY21JWU0vTndXVGYKbGFTQ0w3Z2ptYW1tdkZja0dmRHIrU3RUT004bndhZ2Rsc00rOUhSRlVhbWRybUt4c2tnNDBBZmtzVUFzMm5CbktHMEFOVQo4SGRiUWFDVFFJbVRtS2tVc016WElUVFduY3FoN1JieFVBaDJ1dWxZajN3Z0ZENUw2UXMzWWNEV3hibHhWSXRaN3pXUzhkCnpjeERlZHpTbUIyS251M01GbndmQWRJUS9Bc01YeCs4emllYUV3ZHFTMUdKVUkyQTk1ZTh2Q1FFcGVvbXlaeGorU0lOMU0KMkdVeDdobmUrVm1Tb09lQ0RFelFVRHRZeUxUaHZ5ZmtabHFOTFd1NGhRTTNTNi96MzVlMWpFdEpSV2lhSmF1MDFXeWo1aQpQTlV2VFBFeC9wc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